import {
	seckillAppointment
} from "@/api/shopping/shopping.js"
export default {
	data() {
		return {
			interval: null,
			differ: 1,
			time: {
				hour: '00',
				minute: '00',
				second: '00'
			},
		}
	},
	methods: {
		seckillAppointment() {
			// #ifdef MP-WEIXIN
			wx.requestSubscribeMessage({
				tmplIds: ['ZcMdXI2qqHLPd3rK9nAYxmzPWdWE3gJ83vAJ0-KoC_4'],
				complete: () => {
					// #endif
					if (!this.hasRegister) {
						this.checkLogin();
					} else {
						this.seckillAppointmentRequest();
					}
					// #ifdef MP-WEIXIN
				}
			})
			// #endif
		},
		async seckillAppointmentRequest() {
			const res = await seckillAppointment({
				id: this.id,
				time_from: this.info.time_from
			})
			if (res) {
				this.$Toast.none('预约成功');
				this.getdetail();
			}
		},
		countDown(time) {
			time = new Date(time.replace(/\-/g, '/')).getTime();
			let now = new Date().getTime();
			this.differ = (time - now) / 1000;
			this.killCon = '距离开始还有';
			if ((time - now > 0) && (this.info.status == 2 || this.info.status == 7 || this.info.status == 3)) {
				this.differ = (time - now) / 1000;
				this.killCon = '距离结束还有';
			}
			let remindTime = this.info.remindTime / 1000;
			if ((this.differ < remindTime) && this.killCon == '距离开始还有') {
				this.subscribe = false;
			}
			if (this.differ >= 0) {
				let d = Math.floor(this.differ / (60 * 60 * 24));
				let h = Math.floor(this.differ / (60 * 60) % 24) + d * 24;
				let m = Math.floor(this.differ / 60 % 60);
				let s = Math.floor(this.differ % 60);
				this.time.hour = h < 10 ? `0${h}` : h;
				this.time.minute = m < 10 ? `0${m}` : m;
				this.time.second = s < 10 ? `0${s}` : s;
			}
		}
	}
}
